package cn.mifengkong.appcommon.webview.listener;

import android.app.ProgressDialog;
import android.content.Context;

import com.mifengkong.frtools.system.handler.FRMainLooperHandler;
import com.mifengkong.statistic.umengsignin.BaseUmShareListener;

import java.lang.ref.SoftReference;

/**
 * @author jiangyongxing
 * @date 2018/6/27
 * 描述：
 */

public class MyUMShareListener extends BaseUmShareListener implements SharePromptDialogListener {

    private final SoftReference<Context> mContextSoftReference;
    private ProgressDialog mProgressDialog;

    public MyUMShareListener(final Context context) {
        mContextSoftReference = new SoftReference<>(context);
        runOnMainUiThread(new Runnable() {
            @Override
            public void run() {
                mProgressDialog = new ProgressDialog(context);
                mProgressDialog.setMessage("正在跳转...");
            }
        });

    }

    @Override
    public void onShareStart() {
        runOnMainUiThread(new Runnable() {
            @Override
            public void run() {
                mProgressDialog.show();
            }
        });
    }

    @Override
    public void onShareFinish() {
        dialogDismiss();
        mContextSoftReference.clear();
    }


    @Override
    public void dialogDismiss() {
        if (mProgressDialog != null && mProgressDialog.isShowing()) {
            runOnMainUiThread(new Runnable() {
                @Override
                public void run() {
                    mProgressDialog.dismiss();
                    mProgressDialog = null;
                }
            });
        }

    }

    private void runOnMainUiThread(Runnable runnable) {
        FRMainLooperHandler.getInstance().post(runnable);
    }
}